import { getCurrentInstance, withScopeId } from 'vue'

export function useScopeId(isWith = false) {
  const instance = getCurrentInstance()

  if (!instance) {
    return undefined
  }

  const scopeId: string = (instance.type as any)?.__scopeId
  if (isWith && scopeId) {
    const withId = withScopeId(scopeId)
    return withId
  }
  return scopeId
}
